package com.king.pattem.singleton;

import java.io.Serializable;

/**
 * 懒汉单例模式创新（线程安全）
 * 只有在调用的时候才会初始化
 *
 * @author taomk
 */
public class LazySuperSingleton implements Serializable {

	private LazySuperSingleton() {
		System.out.println("LazySuperSingleton is create");
	}

	private static class SingletonHolder {
		private static LazySuperSingleton instance = new LazySuperSingleton();
	}

	public final static LazySuperSingleton getInstance() {
		return SingletonHolder.instance;
	}

	// 阻止序列化/反序列化时生成新的实例，总是返回当前对象
	private Object readResolve() {
		return SingletonHolder.instance;
	}
}
